Commandline interface arguments processing

Table of Contents

1. Terminology

1.1. Command and argument

Every command-line application has a way of receiving input from users, usually in the form of command-line arguments. A command-line argument is a piece of information provided to the command-line application when it's invoked. These arguments are provided as an array of strings. The first element of the array (argument 0) is typically the name of the command itself.

In the example below, 'my-video-coder' is our command, and the rest are arguments:

my-video-coder encode --input vid1.mp4 vid2.mp4 vid3.mp4 --quality 5

To better understand how these concepts work together, let's break down our example command:

argument # value(s) type
0 my-video-coder command
1 encode subcommand
2 –input option1
3, 4, 5 vid1.mp4 vid2.mp4 vid3.mp4 parameters for –input option
6 –quality option2
7 5 parameter for –quaily option

1.2. Subcommand

Subcommands are arguments that invoke more specific action that a command can perform. They are often used with commands that have multiple functions. In our example, encode is a subcommand of my-video-coder.

1.3. Option

Options are arguments that change the behavior of a command or subcommand. They usually start with a dash (-) or double dash (–). For instance, –input and –quality are options in our example command.

1.4. Parameter

Parameter provides additional information to a command, subcommand or option.

For instance, in our example:

  • 'vid1.mp4 vid2.mp4 vid3.mp4' are parameters for the –input option.
  • '5' is a parameter for the –quality option.

Author: Svjatoslav Agejenko

Created: 2023-10-12 Thu 23:05

Validate